package cn.imu.service.impl;

import cn.imu.entity.UserLog;
import cn.imu.mapper.UserLogMapper;
import cn.imu.service.UserLogService;
import cn.imu.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.Timestamp;


@Service
public class UserLogServiceImpl implements UserLogService {
    @Autowired
    private UserLogMapper userLogMapper;
    @Autowired
    private UserLog userLog;
    @Override
    public int insertUserLog(UserLog userLog) {

        //获得当前系统时间
        Timestamp loginTime = DateUtils.nowDateTime();
        userLog.setLoginTime(loginTime);
        userLogMapper.insertUserLog(userLog);
        return userLog.getId();
    }

    @Override
    public int updateUserLog(int id) {
        userLog.setId(id);
        //获得当前系统时间
        Timestamp logoutTime = DateUtils.nowDateTime();
        userLog.setLogoutTime(logoutTime);
        return userLogMapper.updateUserLog(userLog);
    }
}
